// --- Copyright (c) 2006-2008 Stefan Kyntchev ---
// This software is written and copyrighted by Stefan Kyntchev 
// and BeyondPod Team members. All rights are reserved.
// Author contact: support@beyondpod.mobi
// ------------------------------------------------------------------------
// This file is part of BeyondPod RSS Feed Reader and Podcast manager
// (www.codeplex.com/BeyondPod) 
// BeyondPod is free software: you can redistribute it and/or modify 
// it under the terms of the GNU General Public License as published by 
// the Free Software Foundation, either version 3 of the License, or 
// (at your option) any later version. 
//  
// BeyondPod is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
// GNU General Public License for more details. 
//  
// You should have received a copy of the GNU General Public License
// along with BeyondPod. If not, see <http://www.gnu.org/licenses/>
// ------------------------------------------------------------------------
// COPYRIGHT NOTICE: This copyright notice may NOT be removed, obscured or modified 
// without written consent from the author.
// --- End copyright notice --- 


using System;
using System.Drawing;
using System.Runtime.InteropServices;

namespace svs.Mobile.BeyondScheduler.UI
{
	public class UIHelper
	{
		#region Public Methods

		/// <summary>
		/// 
		/// </summary>
		/// <param name="g">Graphic contest</param>
		/// <param name="p">Pen for the outline</param>
		/// <param name="backColor">Background color for the rectangle</param>
		/// <param name="highlight">The color for the highlight portion</param>
		/// <param name="rc">The rectangle to draw</param>
		/// <param name="size">the size of the rounded corners</param>
		/// <param name="percent_highlighted">what percentage of the whole rectangle to highlight</param>
		public static void DrawRoundedPercentRectangle(Graphics g, Pen p, Color backColor, Color highlight, Rectangle rc,
		                                               Size size, float percent_highlighted)
		{
			Point[] points = new Point[8];

			//prepare brush for background
			Brush fillBrush = new SolidBrush(backColor);
			Brush hiBrush = new SolidBrush(highlight);

			//draw side lines and circles in the corners
			g.DrawLine(p, rc.Left + size.Width/2, rc.Top,
			           rc.Right - size.Width/2, rc.Top);
			g.FillEllipse(fillBrush, rc.Right - size.Width, rc.Top,
			              size.Width, size.Height);
			g.DrawEllipse(p, rc.Right - size.Width, rc.Top,
			              size.Width, size.Height);

			g.DrawLine(p, rc.Right, rc.Top + size.Height/2,
			           rc.Right, rc.Bottom - size.Height/2);
			g.FillEllipse(fillBrush, rc.Right - size.Width, rc.Bottom - size.Height,
			              size.Width, size.Height);
			g.DrawEllipse(p, rc.Right - size.Width, rc.Bottom - size.Height,
			              size.Width, size.Height);

			g.DrawLine(p, rc.Right - size.Width/2, rc.Bottom,
			           rc.Left + size.Width/2, rc.Bottom);
			g.FillEllipse(fillBrush, rc.Left, rc.Bottom - size.Height,
			              size.Width, size.Height);
			g.DrawEllipse(p, rc.Left, rc.Bottom - size.Height,
			              size.Width, size.Height);

			g.DrawLine(p, rc.Left, rc.Bottom - size.Height/2,
			           rc.Left, rc.Top + size.Height/2);
			g.FillEllipse(fillBrush, rc.Left, rc.Top,
			              size.Width, size.Height);
			g.DrawEllipse(p, rc.Left, rc.Top,
			              size.Width, size.Height);

			//fill the background and remove the internal arcs  

			//prepare points for poligon
			points[0].X = rc.Left + size.Width/2;
			points[0].Y = rc.Top + 1;
			points[1].X = rc.Right - size.Width/2;
			points[1].Y = rc.Top + 1;

			points[2].X = rc.Right;
			points[2].Y = rc.Top + size.Height/2;
			points[3].X = rc.Right;
			points[3].Y = rc.Bottom - size.Height/2;

			points[4].X = rc.Right - size.Width/2;
			points[4].Y = rc.Bottom;
			points[5].X = rc.Left + size.Width/2;
			points[5].Y = rc.Bottom;

			points[6].X = rc.Left + 1;
			points[6].Y = rc.Bottom - size.Height/2;
			points[7].X = rc.Left + 1;
			points[7].Y = rc.Top + size.Height/2;

			if (percent_highlighted == 1)
			{
				g.FillPolygon(hiBrush, points);
			}
			else if (percent_highlighted == 0)
			{
				g.FillPolygon(fillBrush, points);
			}
			else
			{
				g.FillPolygon(fillBrush, points);

				float width = points[1].X - points[0].X;
				width *= percent_highlighted;

				Point[] hi = new Point[6];

				hi[0] = points[0];
				hi[1].Y = points[1].Y;
				hi[1].X = points[0].X + (int) Math.Floor(width);
				hi[2].X = hi[1].X;
				hi[2].Y = points[4].Y;
				hi[3] = points[5];
				hi[4] = points[6];
				hi[5] = points[7];

				g.FillPolygon(hiBrush, hi);
			}

			//dispose the brush
			fillBrush.Dispose();
			hiBrush.Dispose();
		}

		#endregion

	}
}